<template>
    <div>
        <div style="margin: 10px 0;">
            <el-input style="width: 200px" placeholder="请输入举报人查询" suffix-icon="el-icon-search"
                      v-model="uname"></el-input>
            <el-input style="width: 200px" placeholder="请输入被举报帖子查询" suffix-icon="el-icon-search" class="ml-5"
                      v-model="ptitle"></el-input>
            <el-button class="ml-5" type="primary" @click="load">搜索</el-button>
            <el-button class="ml-5" v-model="status"  type="danger" @click="have">未处理</el-button>
            <el-button class="ml-5"  v-model="status" type="warning" @click="unhave">已处理</el-button>
            <el-button class="ml-5"  v-model="status" type="primary" @click="allhave">全部处理</el-button>
        </div>

        <el-table :data="tableData" border stripe
                  :header-cell-class-name="'headerBg'"
                  :header-cell-style="{'text-align':'center'}"
                  :cell-style="{'text-align':'center'}" >
            <el-table-column prop="reportid" label="举报id" width="150px">
            </el-table-column>
            <el-table-column prop="uname" label="举报人" width="150px">
            </el-table-column>
            <el-table-column prop="ptitle" label="举报帖子" width="250px">
            </el-table-column>
            <el-table-column prop="reporttime" label="举报时间" width="180px">
            </el-table-column>
            <el-table-column prop="reportcontent" label="举报理由"  width="350px">
            </el-table-column>
            <el-table-column prop="accepted" label="是否受理" width="130px" :formatter="stateFormat">
            </el-table-column>
            <el-table-column label="处理操作">
                <template slot-scope="scope">
                    <el-popconfirm
                            class="ml-5"
                            confirm-button-text='确定'
                            cancel-button-text='我再想想'
                            icon="el-icon-info"
                            icon-color="red"
                            title="你确定禁用吗？"
                            @confirm="makebyunNomal(scope.row.reportid)"
                    >
                        <el-button type="success" slot="reference">禁用该贴 <i class="el-icon-lock"></i></el-button>
                    </el-popconfirm>
                    <el-popconfirm
                            class="ml-5"
                            confirm-button-text='确定'
                            cancel-button-text='我再想想'
                            icon="el-icon-info"
                            icon-color="red"
                            title="你确定忽略吗？"
                            @confirm="ignore(scope.row.reportid)"
                    >
                        <el-button type="danger" slot="reference">忽略举报 <i class="el-icon-remove-outline"></i></el-button>
                    </el-popconfirm>

                </template>
            </el-table-column>
        </el-table>
        <div style="padding: 10px 0">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="pageNum"
                    :page-sizes="[2, 5, 10, 20]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
    export default {
        name:"Report",
        data(){
            return{
                tableData: [],
                total: 0,
                pageNum: 1,
                pageSize: 5,
                ptitle: "",
                uname: "",
                status:"",
                form: {},
                readonly: true
            }
        },
        created() {
            this.load();
        },
        methods:{
            load() {
                this.request.get("/report/page", {
                    params: {
                        pageNum: this.pageNum,
                        pageSize: this.pageSize,
                        uname: this.uname,
                        ptitle: this.ptitle,
                        status:this.status
                    }
                }).then(res => {
                    console.log(res.records)
                    this.tableData = res.records
                    this.total = res.total
                })

            },
            handleSizeChange(pageSize) {
                this.pageSize = pageSize
                this.load()
            },
            handleCurrentChange(pageNum) {
                this.pageNum = pageNum
                this.load()
            },
            stateFormat(row) {
                if (row.accepted === 0) {
                    return '未受理'
                }else {
                    return '已受理'
                }
            },
            makebyunNomal(id){
                this.request.get("/report/unnomal/"+ id).then(res => {
                    if (res) {
                        this.$message.success("禁用成功")
                        this.dialogFormVisible = false
                        this.load()
                    } else {
                        this.$message.error("已为禁用帖子")
                    }
                })
            },

            ignore(id){
                this.request.get("/report/ignore/" + id).then(res => {
                    if (res) {
                        this.$message.success("已忽略")
                        this.dialogFormVisible = false
                        this.load()
                    } else {
                        this.$message.error("错误（ikun）")
                    }
                })
            },
            have(){
                this.status=1
                this.load()
            },

            unhave(){
                this.status=0
                this.load()
            },
            allhave(){
                this.status=2
                this.load()
            },

        }
    }
</script>
<style>
    .headerBg{
        background-color: #eee !important;
    }
</style>